home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11976 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news1.erols.com!newsmaster@erols.com
  2. From: Chris Cobb <ccobb@erols.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: extern consts
  5. Date: 17 Mar 1996 14:15:14 GMT
  6. Organization: CSEG, Inc.
  7. Message-ID: <4ih6pi$tdt@news5.erols.com>
  8. References: <4idbcv$ue2@news7.erols.com> <4ifpmm$2mri@news-s01.ny.us.ibm.net>
  9. NNTP-Posting-Host: ccobb.erols.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
  14.  
  15. bbogard@ibm.net wrote:
  16. >>The above is not possible in C nor in two of the three C++ 
  17. >>compilers I have tried it on
  18. >
  19. >Well, maybe the two other compilers you tried it on weren't ansi C++
  20. >compatible.  Otherwise, that should work in C and C++.  I don't think 
  21. >it is a C++ only thing.  All constants can be defined extern.
  22.  
  23. The reason it is not possible in C is because array sizes must be
  24. declared with constant expressions.  In C, a const variable is not
  25. a constant.  It is just a variable whose value cannot change.  But
  26. this is not the same thing as a constant, such as 1, 2.0, -3.
  27.  
  28. In C++, const by default have static file scope.  Some compilers 
  29. apparently constrain const's to have exclusively this scope.
  30.  
  31. Since this is a very short example which can be typed in in 5 minutes,
  32. I would ask you to try it on your compiler to see if it works.  I'm
  33. trying to assess how widespread this support is and if it's actually
  34. ANSI standard C++.
  35.  
  36. Chris
  37.  
  38.  
  39.  
  40.  
  41.  
  42.